<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>密码修改</title>
</head>
<body>
<!--  修改密码 -->
	<div id="passwordDiv">
		<form id="changePassword" action="${ctx }/user/changePassword" method="post">
			请输入原密码：<input class="oldPassowrd" type="text"> <span>您本次登陆时的密码</span><br> 
			请输入新密码：<input class="newPassowrd" type="text" name="loginPassword"> 新密码不少于6个字符<br> 
			请确认新密码：<input class="cfPassowrd" type="text"> 新密码不少于6个字符<br> 
			<input type="hidden" name="loginAccount" value="${user.loginAccount}">
			<input id="changeBtn" type="button" value="确认修改密码" onclick="chpassowrd()"> <input type="button" value="取消"> 
		</form>
	</div>
</body>
<script>
	function chpassowrd(){
	
		var oldPassowrd = $(".oldPassowrd").val();
		var newPassowrd = $(".newPassowrd").val();
		var cfPassowrd = $(".cfPassowrd").val();
		var lgPassowrd = ${user.loginPassword};
		var loginAccount = $("input[name='loginAccount']").val()
		
		var user = {
	        loginPassword:newPassowrd,
	        loginAccount:loginAccount,
	    };
		if(oldPassowrd != lgPassowrd){
			alert("密码输入错误")
			return;
		}
		
		if(newPassowrd.length<6||newPassowrd !=cfPassowrd){
			alert("新密码请输入6位以上字符，且两次密码需输入一致")
			return;
		}
		$.ajax({
			url:"${ctx }/user/changePassword",
			type:"post",	
			data:user,
			success:function(data){
				if(data==1){
					$("#changeDiv").html("修改密码成功");
					setTimeout(function(){$("#changeDiv").html("")},1000)
				}
			}
		})

	}
	
</script>
</html>

























